<template>
  <KView class="circle-log-view">
    <KView class="circle-log-view-content">
      <circle-log-item v-for="log in logList" :key="log.id" :log="log" @to-praise="toPraiseLog"></circle-log-item>
    </KView>

    <template v-if="loading||circle.pagination.hasNextPage()">
      <KView class="circle-log-view-line"></KView>
      <KView class="circle-log-view-more">
        <KView class="circle-log-view-more-btn" @click="lookMore">展开更多回复</KView>
        <sys-loading v-if="loading" :size="50"></sys-loading>
      </KView>
    </template>
  </KView>
</template>

<script>
  import CircleLogItem from './circleLogItem';
  import SysLoading from 'common/sysLoading';

  export default {
    props: {
      circle: {
        type: Object,
        required: true
      },

      nextDataFun: {
        type: Function,
        required: true
      }
    },

    computed: {
      logList() {
        return this.circle.logList;
      }
    },

    data() {
      return {
        loading: false
      };
    },

    methods: {
      toPraiseLog(log) {
        this.$emit('praise-log', log);
      },

      lookMore() {
        if (this.loading) {
          return;
        }

        let circle = this.circle;
        let pagination = circle.pagination;
        if (!pagination.hasNextPage()) {
          return;
        }

        pagination.nextPage();
        this.loading = true;
        this.nextDataFun(circle).then(() => {
          this.loading = false;
        }).catch(() => {
          this.loading = false;
        });
      }
    },

    components: {
      CircleLogItem,
      SysLoading
    }
  };

</script>

<style lang="scss">
  @import '~style/sysCircleLogView';

</style>
